import Layout from "@/layout/index.vue";
import { createNameComponent } from "@/router/createNode";

export function filterAsyncRouters(routers: Array<any>) {
  const routeAllPathToCompMap = import.meta.glob(`@/**/*.vue`);

  // 存储路由信息
  const resultRouter = [] as any;
  // 遍历传过来的路由
  routers.forEach((router: any) => {
    // 解构
    const tmp = { ...router };
    // 获取到第一层的组件字符串
    const component = tmp.component;
    // 如果 组件地址存在
    if (router.component) {
      // 如果tmp 中 component 等于 Layout 代表第一级别
      if (component == "Layout") {
        // 讲第一层组件地址  对换为本地得Layout 地址
        // tmp.component = createNameComponent(
        //   routeAllPathToCompMap[`../layout/index.vue`]
        // );
        tmp.component = Layout;
      } else {
        // 如果不是第一级 则是其他地址
        // tmp.component = () =>
        //   routeAllPathToCompMap[`../${component}/index.vue`];
        tmp.component = createNameComponent(
          routeAllPathToCompMap[`../${component}/index.vue`]
        );
        // console.log("tmp.component", tmp.component);
      }
    }
    // 有子目录
    if (tmp.children) {
      // 有的话  开始递归生成路由
      tmp.children = filterAsyncRouters(tmp.children);
    }
    resultRouter.push(tmp);
  });
  return resultRouter;
}
export function dataList() {
  return new Promise((res, rej) => {
    res([
      {
        path: "/",
        component: "Layout",
        redirect: "/dashboard",
        meta: {
          title: "message.menu.dashboard.name",
          icon: "sfont system-home",
        },
        children: [
          {
            path: "dashboard",
            component: "views/main/dashboard",
            meta: {
              title: "message.menu.dashboard.index",
              icon: "sfont system-home",
              hideClose: true,
            },
          },
        ],
      },
      {
        path: "/projectManage",
        component: "Layout",
        redirect: "/projectManage/management",
        alwayShow: true,
        meta: {
          title: "message.menu.projectManage.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "management",
            component: "views/main/management",
            // meta: { title: "message.menu.announcement.index" },
            meta: { title: "message.menu.projectManage.projectDetail.name" },
          },
          {
            path: `projectDetail/:id`,
            component: "views/main/projectManage/projectDetail",
            name: "projectDetail",
            meta: {
              title: "message.menu.projectManage.projectDetail.name",
              activeMenu: "/projectManage/management",
            },
            props: (route: any) => ({ query: route.query.q }),
            hidden: true,
          },
          {
            path: "fillInInformation",
            component: "views/main/projectManage/fillInInformation",
            meta: {
              title: "message.menu.projectManage.fillInInformation.name",
              // activeMenu: "/projectManage/projectDetail",
              activeMenu: "/projectManage/management",
            },
            hidden: true,
          },
        ],
      },
      {
        path: "/applyManage",
        component: "Layout",
        redirect: "/applyManage/applyManageDetail",
        alwayShow: true,
        meta: {
          title: "message.menu.applyManage.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "applyManageDetail",
            component: "views/main/applyManage/applyManageDetail",
            meta: { title: "message.menu.applyManage.applyManageDetail.name" },
          },
        ],
      },
      {
        path: "/msgInform",
        component: "Layout",
        redirect: "/msgInform/management",
        alwayShow: true,
        meta: {
          title: "message.menu.msgInform.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "msgInformD",
            component: "views/main/msgInform/msgInformD",
            meta: { title: "message.menu.msgInform.index" },
          },
          {
            path: "timedTask",
            component: "views/main/msgInform/timedTask",
            meta: { title: "message.menu.timedTask.name" },
          },
        ],
      },
      // statisticAnalysis
      {
        path: "/auditManage",
        component: "Layout",
        redirect: "/auditManage/userAudit",
        alwayShow: true,
        meta: {
          title: "message.menu.auditManage.name",
          icon: "sfont system-component",
        },
        children: [
          {
            path: "userAudit",
            component: "views/main/auditManage/userAudit",
            meta: { title: "message.menu.auditManage.userAudit.name" },
          },
        ],
      },
      {
        path: "/statisticAnalysis",
        component: "Layout",
        // redirect: "/auditManage/userAudit",
        alwayShow: true,
        meta: {
          title: "message.menu.statisticAnalysis.name",
          icon: "sfont system-component",
        },
      },
      {
        path: "/trade",
        component: "Layout",
        redirect: "/trade/tradeDetail",
        alwayShow: true,
        meta: {
          title: "message.menu.trade.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "tradeDetail",
            component: "views/main/trade/tradeDetail",
            meta: { title: "message.menu.trade.tradeDetail.name" },
          },
          {
            path: "notices",
            component: "views/main/trade/notices",
            meta: { title: "message.menu.trade.notices.name" },
          },
        ],
      },
      {
        path: "/system",
        component: "Layout",
        redirect: "/system/userManagement",
        alwayShow: true,
        meta: {
          title: "message.menu.systemName.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "userManagement",
            component: "views/main/system/userManagement",
            meta: { title: "message.menu.userManagement.name" },
          },
          {
            path: "roleManagement",
            component: "views/main/system/roleManagement",
            meta: { title: "message.menu.roleManagement.name" },
          },
          {
            path: "theLog",
            component: "views/main/system/theLog",
            meta: { title: "message.menu.theLog.name" },
          },
          {
            path: "resource",
            component: "views/main/system/resource",
            meta: { title: "message.menu.resource.name" },
          },
          {
            path: "basic",
            component: "views/main/system/basic",
            meta: { title: "message.menu.basic.name" },
          },
        ],
      },
      {
        path: "/systemManagement",
        component: "Layout",
        redirect: "/systemManagement/formConfiguration",
        alwayShow: true,
        meta: {
          title: "message.menu.systemManagement.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "formConfiguration",
            component: "views/main/systemManagement/formConfiguration",
            meta: {
              title: "message.menu.systemManagement.formConfiguration.name",
            },
          },
          {
            path: "dynamicTable",
            component: "views/main/systemManagement/dynamicTable",
            meta: { title: "message.menu.dynamicTable.name" },
          },
          {
            path: "editformConfiguration",
            component: "views/main/systemManagement/editformConfiguration",
            meta: {
              title: "message.menu.systemManagement.formConfiguration.name",
              activeMenu: "/systemManagement/formConfiguration",
            },
            hidden: true,
          },
        ],
      },
      {
        path: "/statisticChildren",
        component: "Layout",
        redirect: "/statisticChildren/statisticAnalysis",
        alwayShow: true,
        meta: {
          title: "message.menu.statisticChildren.name",
          icon: "sfont system-menu",
        },
        children: [
          {
            path: "statisticAnalysis",
            component: "views/main/statisticChildren/statisticAnalysis",
            meta: {
              title: "message.menu.statisticChildren.statisticAnalysis.name",
            },
          },
        ],
      },
    ]);
  });
}
